package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import pojo.Book;
import pojo.User;
import util.DBUtil;
import dao.BookDao;

public class BookDaoImpl implements BookDao{

	@Override
	public List<Book> findAll() {
		Connection con=null;
		con=DBUtil.createConnection();
		PreparedStatement ps=null;
		ResultSet rs=null;
		String sql="select * from books";
		Book book=null;
		List<Book> books=new ArrayList<Book>(); 
		try {
			ps=con.prepareStatement(sql);
			
			rs=ps.executeQuery();
			while(rs.next())
			{
				book=new Book();
				book.setId(rs.getString(1));
				book.setName(rs.getString(2));
				book.setPath(rs.getString(3));
				books.add(book);
			}
		} catch (Exception e) {
			
		}finally
		{
			DBUtil.close(null,con,ps);
		}
		return books;
	}

}
